﻿
  <div class="modal fade" id="resetpasswordModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title" id="myModalLabel">重置密码</h4>
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
            &times;
          </button>

        </div>
        <div class="modal-body">

     
              <form id="resetpassword_form" class="needs-validation" novalidate>
                <input type="hidden" id="restuserid" name="restuserid" value="" />
                <div class="form-group">
                  <label class="form-label" for="restusername">用户名</label>
                  <input type="text" class="form-control" id="restusername" name="restusername" readonly required>
                </div>
                <div class="form-group">
                  <label class="form-label" for="restpassword">新密码</label>
                  <input type="password" class="form-control" id="restpassword" name="restpassword" required minlength="4">
                  <div class="invalid-tooltip">
                    请输入新密码
                  </div>
                </div>
                <div class="form-group">
                  <label class="form-label" for="restpasswordConfirm">再输入新密码</label>
                  <input type="password" class="form-control" id="restpasswordConfirm" name="restpasswordConfirm" required minlength="4">
                  <div class="invalid-tooltip">
                    请输入正确的密码
                  </div>
                </div>


              </form>
              <script>
                // Example starter JavaScript for disabling form submissions if there are invalid fields
                (function () {
                  'use strict';
                  window.addEventListener('load', function () {
                    // Fetch all the forms we want to apply custom Bootstrap validation styles to
                    var txtPassword = document.getElementById("restpassword");
                    var txtConfirmPassword = document.getElementById("restpasswordConfirm");
                    txtPassword.onchange = ConfirmPassword;
                    txtConfirmPassword.onkeyup = ConfirmPassword;
                    function ConfirmPassword() {
                      txtConfirmPassword.setCustomValidity("");
                      if (txtPassword.value != txtConfirmPassword.value) {
                        txtConfirmPassword.setCustomValidity("新密码不匹配.");
                      }
                    }
                  }, false);
                })();

              </script>
      


        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">
            取消
          </button>
          <button type="button" onclick="setpassword()" class="btn btn-primary">
            重置密码
          </button>
        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div>
<script type="text/javascript">
   
   function showresetform(userid, username) {
      $('#restusername').val(username);
      $('#restuserid').val(userid);
      $('#resetpasswordModal').modal('toggle');
    }
  function setpassword() {
    var form = document.getElementById("resetpassword_form");
    if (form.reportValidity()) {
      var id = $('#restuserid').val();
      var password = $('#restpassword').val();
      var url = "/AccountManage/ResetPassword?id=" + id + "&newPassword=" + password;

      $.get(url, function (res) {
        if (res.success) {
          $('#resetpasswordModal').modal('toggle');
          reload();
        } else {
          $.messager.alert('错误', res.err, 'error')
        }
      });

    } else {
      form.classList.add('was-validated');
    }

  }
</script>